package com.ksd.modules.members.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.members.po.AdminUserSavePO;
import com.ksd.modules.members.po.AdminUserSearchPO;
import com.ksd.modules.members.service.IAdminUserService;
import com.ksd.modules.members.vo.AdminUserVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台up主用户 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-15
 */
@RestController
public class AdminUserController extends BaseController {


    @Autowired
    private IAdminUserService adminUserService;

    /**
     * 查询首页平台用户模板接口
     * @param adminUserSearchPO
     * @return
     */
    @PostMapping("/users/list")
    public R<Page<AdminUserVo>> findAdminUsers(@Validated @RequestBody AdminUserSearchPO adminUserSearchPO){
        return R.data(adminUserService.findAdminUsers(adminUserSearchPO));
    }

    /**
     * 【平台用户】- 回收站
     * @return
     */
    @PostMapping("/users/recyle")
    public R<Page<AdminUserVo>> findAdminUsersRecyle(@Validated @RequestBody AdminUserSearchPO adminUsersSearchPO){
        return R.data(adminUserService.findAdminUsersRecyle(adminUsersSearchPO));
    }

    /**
     * 【平台用户】 - 保存和更新
     * @param adminUsersSavePO
     * @return
     */
    @PostMapping("/users/saveupdate")
    @ApiLog("【平台用户】 - 保存和更新")
    @RepeatSubmit
    public R<AdminUserVo> saveUpdateAdminUser(@Validated @RequestBody AdminUserSavePO adminUsersSavePO){
        return R.data(adminUserService.saveUpdateAdminUser(adminUsersSavePO));
    }

    /**
     * 【平台用户】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/users/get/{id}")
    public R<AdminUserVo> getAdminUserById(@PathVariable("id")Long id){
        return R.data(adminUserService.getAdminUserById(id));
    }

    /**
     * 【平台用户】 - 根据id删除平台用户
     * @param id
     * @return
     */
    @PostMapping("/users/del/{id}")
    @ApiLog("【平台用户】 - 根据id删除平台用户 ")
    public R<Boolean> deleteAdminUserById(@PathVariable("id")Long id){
        return R.data(adminUserService.deleteAdminUserById(id));
    }

    /**
     * 【平台用户】- 根据id恢复删除
     *
     * @param id
     * @return
     */
    @PostMapping("/users/recover/{id}")
    @ApiLog("【平台用户】- 根据id恢复删除")
    @RepeatSubmit
    public R<Boolean> recoverByIdAdminUser(@PathVariable("id") Long id) {
        return R.data(adminUserService.recoverByIdAdminUser(id));
    }

    /**
     * 【平台用户】- 批量逻辑删除
     *
     * @return
     */
    @PostMapping("/users/batch/dels")
    @ApiLog("【平台用户】- 批量逻辑删除")
    @RepeatSubmit
    public R<Boolean> bacthDeletesAdminUser(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserService.bacthDeletesAdminUser(batchIdsPO));
    }


    /**
     * 【平台用户】- 批量恢复
     *
     * @return
     */
    @PostMapping("/users/batch/recover")
    @ApiLog("【平台用户】- 批量恢复")
    @RepeatSubmit
    public R<Boolean> batchRecoversAdminUser(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserService.batchRecoversAdminUser(batchIdsPO));
    }

    /**
     * 【平台用户】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/users/batch/remove")
    @ApiLog("【平台用户】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminUser(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserService.batchRemovesAdminUser(batchIdsPO));
    }

    /**
     * 【平台用户】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/users/remove/{id}")
    @ApiLog("【平台用户】- 根据ID恢复删除")
    public R<Boolean> removeAdminUserById(@PathVariable("id")Long id){
        return R.data(adminUserService.removeAdminUserById(id));
    }

    /**
     * 【平台用户】- 修改状态
     *
     * @return
     */
    @PostMapping("/users/status/{id}/{field}")
    @ApiLog("【平台用户】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminUserService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminUserService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【下载】-批量上架
     *
     * @return
     */
    @PostMapping("/users/batch/up")
    @ApiLog("【下载】-批量上架")
    @RepeatSubmit
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserService.batchUps(batchIdsPO));
    }

    /**
     * 【下载】-批量下架
     *
     * @return
     */
    @PostMapping("/users/batch/down")
    @ApiLog("【下载】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserService.batchDowns(batchIdsPO));
    }
}
